package org.example.controller.shanjia;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.dto.CategoryDTO;
import org.example.dto.OPtionsDTO;
import org.example.dto.SpecDTO;
import org.example.entity.Category;
import org.example.result.Result;
import org.example.service.ShanpinguigeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shanjia/shanpinguige")
@Slf4j
@Api(tags = "商品规格相关接口")
public class GlshanpinguigeController {
    @Autowired
    ShanpinguigeService shanpinguigeService;


    /**
     * 商品规格查询
     *
     * @param
     * @return
     */
    @GetMapping("/cx")
    @ApiOperation(value = "商品规格查询")
    public Result<List<Category>> cx(@RequestParam( "username") String username){
        log.info("商品规格查询：{}", username);
        return Result.success(shanpinguigeService.cx(username));
    }

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping("/xz")
    @ApiOperation(value = "商品规格分类新增")
    public Result xzfele(@RequestBody CategoryDTO categoryDTO) {
        log.info("商品规格分类新增：{}", categoryDTO);
        shanpinguigeService.xzfele(categoryDTO);
        return Result.success();
    }

    /**
     *
     *删除分类
     * @param username
     * @param id
     * @return
     */
    @DeleteMapping("/sc")
    @ApiOperation(value = "商品规格分类删除")
    public  Result scfele(@RequestParam( "username") String username,@RequestParam( "id") String id){
        log.info("删除分类：{}",username,id);
        shanpinguigeService.scfele(username,id);
        return Result.success();
    }

    /**
     * 新增规格
     * @param specDTO
     * @return
     */
    @PostMapping("/xzgui")
    @ApiOperation(value = "商品规格新增")
    public Result xzgui(@RequestBody SpecDTO specDTO) {
        log.info("商品规格新增：{}", specDTO);
        shanpinguigeService.xzgui(specDTO);
        return Result.success();
    }

    /**
     * 删除规格
     * @param
     * @return
     */
    @DeleteMapping("/scgui")
    @ApiOperation(value = "商品规格删除")
    public Result scgui(@RequestParam( "username") String username,@RequestParam( "id") String id,@RequestParam( "name") String name) {
        log.info("商品规格删除：{}", username,id,name);
        shanpinguigeService.scgui(username,id,name);
        return Result.success();
    }

    /**
     * 新增规格值
     * @param
     * @return
     */
    @PostMapping("/xzguizhi")
    @ApiOperation(value = "商品规格值新增")
    public Result xzguizhi(@RequestBody OPtionsDTO oPtionsDTO) {
        log.info("商品规格值新增：{}", oPtionsDTO);
        shanpinguigeService.xzguizhi(oPtionsDTO);
        return Result.success();
    }
    /**
     * 删除规格值
     * @param
     * @return
     */
    @DeleteMapping("/scguizhi")
    @ApiOperation(value = "商品规格值删除")
    public Result scguizhi(@RequestParam( "name") String name,@RequestParam( "categoryid") String id,
                           @RequestParam( "specname") String specname,
                           @RequestParam( "username") String username) {
        log.info("商品规格删除：{},{},{}",name,id,specname);
        shanpinguigeService.scguizhi(name,id,specname,username);
        return Result.success();
    }


}
